package com.zx.common;/**
 * Author:JasonZ
 * Data:2023/4/19
 */

import java.util.Objects;
import java.util.stream.Stream;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @program: ecommerce-parent
 * @description:
 * @author: JasonZ
 * @create: 2023-04-19 09:36
 **/
@AllArgsConstructor
@Getter
public enum GoodsStatus {
    ON_LINE(101, "上线"),
    OFF_LINE(102, "下线"),
    STOCK_OUT(103, "库存不足");
    private Integer code;   // 状态码
    private String description; // 描述

    public static GoodsStatus of(Integer code) {
        // 校验
        Objects.requireNonNull(code);
        return Stream.of(values()).filter(bean -> bean.code.equals(code))
                .findAny()
                .orElseThrow(() -> new IllegalArgumentException("code: " + code + " not exists"));
    }
}

